From: Michael Catanzaro Date: Sun, 27 Jul 2025 14:40:51 +0000 (+0200) Subject: portalHelper: Schedule recheck if it's too soon to recheck X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~112^2^2~25 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=f9c41ea665dc0dd175ba5933c867c4551c4acf95;p=gnome-shell.git portalHelper: Schedule recheck if it's too soon to recheck Currently we have a 30 second limit on rechecks. A recheck that would violate the limit is simply dropped. This causes the portal helper to never close itself. Instead, schedule a future recheck for as soon as the timeout expires. This will put an upper bound on how long the portal helper will unnecessarily remain open. (I've also changed the logic to unconditionally emit CANCELLED in vfunc_close_request(), since this seems more correct. This won't actually affect anything, because gnome-shell just ignores the CANCELLED status, but in theory it's nice to end things with an indication that we are finished. Otherwise, CANCELLED will never be emitted.) Closes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7790 Part-of: --- diff --git a/js/portalHelper/main.js b/js/portalHelper/main.js index 5ae536c3b..af49d51a4 100644 --- a/js/portalHelper/main.js +++ b/js/portalHelper/main.js @@ -134,7 +134,7 @@ class PortalWindow extends Gtk.ApplicationWindow { this._originalUrl = url; this._statusChangedCallback = statusChangedCallback; this._lastRecheck = 0; - this._recheckAtExit = false; + this._recheckTimeoutId = 0; this._networkSession = WebKit.NetworkSession.new_ephemeral(); this._networkSession.set_proxy_settings(WebKit.NetworkProxyMode.NO_PROXY, null); @@ -180,10 +180,12 @@ class PortalWindow extends Gtk.ApplicationWindow { } vfunc_close_request() { - if (this._recheckAtExit) + if (this._recheckTimeoutId) { this._statusChangedCallback(PortalHelperResult.RECHECK); - else - this._statusChangedCallback(PortalHelperResult.CANCELLED); + GLib.source_remove(this._recheckTimeoutId); + this._recheckTimeoutId = 0; + } + this._statusChangedCallback(PortalHelperResult.CANCELLED); return false; } @@ -254,23 +256,24 @@ class PortalWindow extends Gtk.ApplicationWindow { // (but ratelimit the checks, we don't want to spam // nmcheck.gnome.org for portals that have 10 or more internal // redirects - and unfortunately they exist) - // If we hit the rate limit, we also queue a recheck - // when the window is closed, just in case we miss the - // final check and don't realize we're connected - // This should not be a problem in the cancelled logic, - // because if the user doesn't want to start the login, - // we should not see any redirect at all, outside this._uri - - let now = GLib.get_monotonic_time(); - let shouldRecheck = (now - this._lastRecheck) > - CONNECTIVITY_RECHECK_RATELIMIT_TIMEOUT; - - if (shouldRecheck) { - this._lastRecheck = now; - this._recheckAtExit = false; - this._statusChangedCallback(PortalHelperResult.RECHECK); - } else { - this._recheckAtExit = true; + + if (this._recheckTimeoutId === 0) { + const now = GLib.get_monotonic_time(); + const timeSinceLastRecheck = this._lastRecheck ? now - this._lastRecheck : 0; + + if (timeSinceLastRecheck > CONNECTIVITY_RECHECK_RATELIMIT_TIMEOUT || this._lastRecheck === 0) { + this._lastRecheck = now; + this._statusChangedCallback(PortalHelperResult.RECHECK); + } else { + const seconds = + (CONNECTIVITY_RECHECK_RATELIMIT_TIMEOUT - timeSinceLastRecheck) / + GLib.USEC_PER_SEC; + this._recheckTimeoutId = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, seconds, () => { + this._statusChangedCallback(PortalHelperResult.RECHECK); + this._recheckTimeoutId = 0; + return GLib.SOURCE_REMOVE; + }); + } } // Update the URI, in case of chained redirects, so we still